/*
 * SatComm.cpp
 *
 *  Created on: Nov 9, 2014
 *      Author: root
 */

#include"SatPassComm.h"



bool ListenInitMSG(Connection server,int TimeOutSec)
{
	Message msg;

	//with timeout
	bool received = server.receiveWithTimeout(&msg , 2);

		if (received && msg.type() == msg.INIT)
			return true;
		else
			return false;
}

bool SendACKandWaitForMSGreceive(Connection server,int TimeOutSec,Message &msg)
{
	Message ACKmsg;
	ACKmsg.set_type(ACKmsg.ACK);
	bool received =server.sendAndWaitForReceiveWithTimeout(ACKmsg,&msg,TimeOutSec);
	return received;
}

bool SendSAT_I_DATAandWaitForMSGreceive(Connection server,int TimeOutSec,Message &msg)
{
	Message DATAmsg;
	DATAmsg.set_type(DATAmsg.SAT_I_DATA);
	DATAmsg.set_content(getSatData());
	bool received =server.sendAndWaitForReceiveWithTimeout(DATAmsg,&msg,TimeOutSec);
	return received;

}

bool waitForMSG(Connection server,int TimeOutSec,Message &msg)
{
	//with timeout
	bool received = server.receiveWithTimeout(&msg , TimeOutSec);
	return received;
}

bool sendACK(Connection server,int TimeOutSec)
{
	Message msg;
	msg.set_type(msg.ACK);
	bool sent  = server.sendWithTimeout(msg , TimeOutSec);
	return sent;
}

bool isEND_CMDmsg(Message request)
{
	if (request.type()==request.END_CMD)
			return true;
		else
			return false;
}

bool isCMD_TO_SAT_Imsg(Message request)
{
	if (request.type()==request.CMD_TO_SAT_I)
			return true;
		else
			return false;

}

bool isACKmsg(Message request)
{
	if (request.type()==request.ACK)
			return true;
		else
			return false;

}

bool isGO_CMDmsg(Message request)
{
	if (request.type()==request.GO_CMD)
			return true;
		else
			return false;

}

string getSatData()
{
	return "SatData123";
}
